package com.zhiyou100.taxi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou100.taxi.dao.CarCheckMapper;
import com.zhiyou100.taxi.entity.CarCheck;
import com.zhiyou100.taxi.entity.CarCheckExample;
import com.zhiyou100.taxi.service.CarCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
import java.util.List;

/**
 * @author zhaokuii11@163.com
 * @create 2021-11-25 17:25
 * @Description
 */
@Service
@Transactional
public class CarCheckServiceImpl implements CarCheckService {
    @Autowired
    CarCheckMapper carCheckMapper;

    @Override
    public List<CarCheck> getAll() {
        return carCheckMapper.selectByExample(null);
    }

    @Override
    public int deleteByCarId(String crId) {
        CarCheckExample example = new CarCheckExample();
        CarCheckExample.Criteria criteria = example.createCriteria();
        criteria.andCarIdEqualTo(crId);
        return carCheckMapper.deleteByExample(example);

    }

    @Override
    public PageInfo<CarCheck> getCarPage(Integer pageNum) {
        PageHelper.startPage(pageNum, 5);
        PageInfo<CarCheck> carCheckPageInfo = new PageInfo<>(getAll());
        return carCheckPageInfo;
    }

    @Override
    public int deleteByPrimaryKeys(HashSet<String> set) {
        try {
            set.forEach(c -> {
                carCheckMapper.deleteByPrimaryKey(c);
            });
            return set.size();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }

    @Override
    public CarCheck getOneByPrimaryKey(String carCheckId) {
        CarCheck carCheck = carCheckMapper.selectByPrimaryKey(carCheckId);
        return carCheck;
    }

    @Override
    public String getPrimaryKey() {
        return "car_check_" + carCheckMapper.selectPrimaryKey();
    }


    @Override
    public int insert(CarCheck carCheck) {
        return carCheckMapper.insert(carCheck);
    }

    @Override
    public int updateByPrimaryKey(CarCheck carCheck) {
        return carCheckMapper.updateByPrimaryKey(carCheck);
    }
}
